package com.gluxen.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.gluxen.dao.IBaseDao;
import com.gluxen.entity.Gift;

@Service
public class GiftService extends BaseService implements IGiftService{
	@Resource
	IBaseDao baseDao;
	
	    //@MyLog(operationName = "添加礼品信息", operationType = "add")
		@Override
		public void addGift(Gift gift) {
			baseDao.add(gift);
		}
	
		//@MyLog(operationName = "删除礼品", operationType = "delete")
		@Override
		public void deleteGift(Gift gift) {
			baseDao.delete(gift);
		}
		
		//@MyLog(operationName = "修改礼品信息", operationType = "update")
		@Override
	    public void updateGift(Gift gift) throws Exception {
			baseDao.update(gift);
		}
	
		@SuppressWarnings("unchecked")
		@Override
		public List<Gift> queryGift(){
			String hql = "from Gift o where o.isDelete=0";
			List<Gift> list= (List<Gift>) baseDao.getObjectList(hql);
			return list;
		}
		
		@SuppressWarnings("unchecked")
		@Override
		public List<Gift> queryGiftbyname(String nickname){
			String hql = "from Gift o where o.isDelete=0 and o.name='"+nickname+"'";
			List<Gift> list= (List<Gift>) baseDao.getObjectList(hql);
			return list;
		}

		@SuppressWarnings({ })
		@Override
		public Gift queryGiftbyId(int id){
			String hql = "from Gift o where o.isDelete=0 and o.id = '"+id+"'";
			Gift gift = (Gift) baseDao.getUnqueResult(hql, null);
			return gift;
		}
		
		//切面处理，得到日志信息
	     //@MyLog(operationName = "批量删除礼品", operationType = "delete")
		@Override
			public void deleteGift(String[] ids) {
				StringBuffer sb = new StringBuffer();
				for (int i = 0; i < ids.length - 1; i++)
					sb.append(ids[i] + ",");
				sb.append(ids[ids.length - 1]);
				delete(Gift.class, sb.toString());
			}
}
